package com.frontend.api.controller;

import com.common.dto.CommentDTO;
import com.common.service.CommentService;
import com.util.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(tags = "CommentController", value = "评论接口")
public class CommentController {

    @Resource
    private CommentService commentService;

    @ApiOperation("获取文章的评论接口")
    @RequestMapping(value = "/article/comment/{id}")
    public CommonResult getCommentByArticle(
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
            @PathVariable("id") Long articleId
    ) {
        List<CommentDTO> commentDTOS = commentService.selectPageByArticleId(page, pageSize, articleId);
        return CommonResult.success(commentDTOS);
    }

}
